package com.hong.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(value ="缓存用例",tags = {"缓存用例"})
@RestController
@RequestMapping("/redis")
public class RedisController {


    @Autowired
    private RedisTemplate redisTemplate;


    @ApiOperation("list")
    @PostMapping("list")
    public String list(@RequestBody Object body){


        redisTemplate.opsForList().leftPush("send_k_test",body);

        return "";
    }

    @ApiOperation("list/search")
    @GetMapping("list/search")
    public Object getList(){
        List list = redisTemplate.opsForList().range("send_k_test", 0, -1);



        Object sendKTest1 = redisTemplate.opsForList().index("send_k_test", 0);


        return list;
    }

    @ApiOperation("set")
    @PostMapping("set")
    public Object set(@RequestParam String value){
        redisTemplate.opsForSet().add("send_K_set",value);
        return "success";
    }


}
